package ability160

import (
    "log"
    "errors"
    "topsdk"
    "topsdk/ability160/request"
    "topsdk/ability160/response"
    "topsdk/util"
)

type Ability160 struct {
    Client *topsdk.TopClient
}

func NewAbility160(client *topsdk.TopClient) *Ability160{
    return &Ability160{client}
}

/*
    获取订单详情页跳转入口配置
*/
func (ability *Ability160) TaobaoOpentradeOrderdetailEntryGet(req *request.TaobaoOpentradeOrderdetailEntryGetRequest,session string) (*response.TaobaoOpentradeOrderdetailEntryGetResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability160 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.opentrade.orderdetail.entry.get",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoOpentradeOrderdetailEntryGetResponse{}
    if(err != nil){
        log.Println("taobaoOpentradeOrderdetailEntryGet error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    交易开放获取商品绑定信息
*/
func (ability *Ability160) TaobaoOpentradeToolsItemsQuery(req *request.TaobaoOpentradeToolsItemsQueryRequest,session string) (*response.TaobaoOpentradeToolsItemsQueryResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability160 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.opentrade.tools.items.query",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoOpentradeToolsItemsQueryResponse{}
    if(err != nil){
        log.Println("taobaoOpentradeToolsItemsQuery error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    交易开放商品解绑
*/
func (ability *Ability160) TaobaoOpentradeToolsItemsUnbind(req *request.TaobaoOpentradeToolsItemsUnbindRequest,session string) (*response.TaobaoOpentradeToolsItemsUnbindResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability160 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.opentrade.tools.items.unbind",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoOpentradeToolsItemsUnbindResponse{}
    if(err != nil){
        log.Println("taobaoOpentradeToolsItemsUnbind error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
/*
    交易开放商品绑定
*/
func (ability *Ability160) TaobaoOpentradeToolsItemsBind(req *request.TaobaoOpentradeToolsItemsBindRequest,session string) (*response.TaobaoOpentradeToolsItemsBindResponse,error) {
    if(ability.Client == nil) {
        return nil,errors.New("Ability160 topClient is nil")
    }
    var jsonStr,err = ability.Client.ExecuteWithSession("taobao.opentrade.tools.items.bind",req.ToMap(),req.ToFileMap(),session)
    var respStruct = response.TaobaoOpentradeToolsItemsBindResponse{}
    if(err != nil){
        log.Println("taobaoOpentradeToolsItemsBind error",err)
        return &respStruct,err
    }
    err = util.HandleJsonResponse(jsonStr, &respStruct)
    if(respStruct.Body == "" || len(respStruct.Body) == 0) {
        respStruct.Body = jsonStr
    }
    return &respStruct,err
}
